const app = getApp();

Page({
  data: {
    userInfo: {
      name: '笑看人生',
      level: 3,
      avatar: 'https://dummyimage.com/240x240/cccccc/333333.png&text=用户'
    },
    stats: {
      follow: 154,
      collect: 24,
      like: 384,
      footprint: 1254
    },
    orderTypes: [
      { id: 1, name: '家政护理', icon: '/images/order-home.png', type: 'home', bgColor: '#E8F9F3' },
      { id: 2, name: '康复理疗', icon: '/images/order-health.png', type: 'health', bgColor: '#F3E8F9' },
      { id: 3, name: '上门体检', icon: '/images/order-check.png', type: 'check', bgColor: '#FFE8E8' }
    ],
    functionList: [
      { id: 1, name: '优惠券', icon: '/images/coupon.png', type: 'coupon' },
      { id: 2, name: '积分', icon: '/images/points.png', type: 'points' },
      { id: 3, name: '我参加的活动', icon: '/images/my-activity.png', type: 'activity' },
      { id: 4, name: '我的评价', icon: '/images/my-review.png', type: 'review' },
      { id: 5, name: '帮助与支持', icon: '/images/help.png', type: 'help' },
      { id: 6, name: '设置', icon: '/images/settings.png', type: 'settings' }
    ]
  },

  onLoad() {
    this.loadUserInfo();
  },

  loadUserInfo() {
    // 从全局数据或本地存储加载用户信息
    const globalUserInfo = app.globalData.userInfo;
    if (globalUserInfo) {
      this.setData({
        'userInfo.name': globalUserInfo.name || '笑看人生',
        'userInfo.avatar': globalUserInfo.avatar || this.data.userInfo.avatar
      });
    }
  },

  // 编辑用户名
  onEditName() {
    wx.showToast({
      title: '编辑昵称',
      icon: 'none'
    });
  },

  // 个人主页
  onHomepage() {
    wx.showToast({
      title: '个人主页',
      icon: 'none'
    });
  },

  // 统计数据点击
  onStatTap(e) {
    const type = e.currentTarget.dataset.type;
    const titleMap = {
      follow: '我的关注',
      collect: '我的收藏',
      like: '我的点赞',
      footprint: '我的足迹'
    };
    wx.showToast({
      title: titleMap[type],
      icon: 'none'
    });
  },

  // 订单类型点击
  onOrderType(e) {
    const type = e.currentTarget.dataset.type;
    wx.navigateTo({
      url: `/pages/mine/order/order?type=${type}`
    });
  },

  // 功能项点击
  onFunctionTap(e) {
    const type = e.currentTarget.dataset.type;
    const pageMap = {
      activity: '/pages/mine/my-activity/my-activity',
      settings: '/pages/mine/settings/settings',
      help: '/pages/mine/customer-service/customer-service'
    };

    if (pageMap[type]) {
      wx.navigateTo({
        url: pageMap[type]
      });
    } else {
      wx.showToast({
        title: '功能开发中',
        icon: 'none'
      });
    }
  }
})
